#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int fib(int n) {
        return (n <= 1) ? n : fib(n - 1) + fib(n - 2);
    }
};

class Solution {
public:
    int fib(int n) {
        if (n <= 1)
            return n;
        vector<int> dp(n + 1);
        dp[0] = 0;
        dp[1] = 1;
        for (int i = 2; i < n + 1; i++)
            dp[i] = dp[i - 1] + dp[i - 2];
        return dp[n];
    }
};

class Solution {
public:
    int fib(int n) {
        if (n <= 1)
            return n;
        int tmp1 = 0;
        int tmp2 = 1;
        int sum = 0;
        for (int i = 2; i < n + 1; i++)
        {
            sum = tmp1 + tmp2;
            tmp1 = tmp2;
            tmp2 = sum;
        }
        return sum;
    }
};

class Solution {
public:
    int climbStairs(int n) {
        if (n <= 2)
            return n;
        vector<int> dp(n + 1);
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i <= n; i++)
            dp[i] = dp[i - 1] + dp[i - 2];
        return dp[n];
    }
};

class Solution {
public:
    int climbStairs(int n) {
        if (n <= 2)
            return n;
        int tmp1 = 1;
        int tmp2 = 2;
        int sum = 0;
        for (int i = 3; i <= n; i++)
        {
            sum = tmp1 + tmp2;
            tmp1 = tmp2;
            tmp2 = sum;
        }
        return sum;
    }
};

class Solution {
public:
    int minCostClimbingStairs(vector<int>& cost) {
        vector<int> v(cost.size() + 1);
        v[0] = 0;
        v[1] = 0;
        for (int i = 2; i < v.size(); i++)
        {
            v[i] = ((v[i - 1] + cost[i - 1]) > (v[i - 2] + cost[i - 2])) ? (v[i - 2] + cost[i - 2]) : (v[i - 1] + cost[i - 1]);
        }
        return v[v.size() - 1];
    }
};